/*
 * @(#)SimulationFrame.java	  06.09.1997  Robert Denda&Didier Gutacker
 * 
 */

import java.awt.*;
import java.lang.*;

/** 
 * Die Klasse SimulationFrame stellt die graphische Schnittstelle der Simulation zu
 * dem Benutzer dar. 
 *
 * @author 	Robert Denda&Didier Gutacker
 * @version     1.1, 06.09.1997
 * @see RollCanvas
 * @see Legende
 * @see ButtonPanel
 */

/**
 *
 * Changes / Enhancements :
 *
 * 1) replaced system.exit(0) by this.hide() and this.dispose() to avoid
 *    problems closing the Window in Win 95 
 * 2) Made abstract and adapted to the new structure with two applets
 * 
 * Changes made by Didier Gutacker in August 1997
 *
 */

public abstract class SimulationFrame extends Frame {

  // debugging 
  debug DEBUG = new debug();

  // text
  public TextMethods text;
  public boolean english;

  public int animationSpeed = 1;
  
  public Simulation simulation;

  public boolean initialized = false;

  public int ROWS = 5, COLS = 80;

  public TextArea textArea;
  public TextArea textArea2;
  public Legende index;
  public boolean demoRunning = false;

  public Menu windowMenu;
  public Menu editMenu;
  public Menu helpMenu;
  public MenuItem quitMenuItem;
  public MenuItem changeLanguageMenuItem;
  public Menu simulationSpeedMenu;
  public MenuItem simulationSpeedSlowMenuItem;
  public MenuItem simulationSpeedNormalMenuItem;
  public MenuItem simulationSpeedFastMenuItem;
  public MenuItem startDemoMenuItem;
  public MenuItem newMenuItem;
  public MenuItem introductionMenuItem;
  public MenuItem infoMenuItem;
  public MenuItem speechLanguageMenuItem;

  public Panel upperRow;
  public Panel lowerRow;
  public Panel lowestRow;

  public ThreadGroup tg;

  public boolean isServer = false;
  public boolean isClient = false;
  public SimulationServer server;
  public SimulationClient client;
 
  /** 
   * Liefert die gemeinsame Thread Gruppe
   */

  public final ThreadGroup getThreadGroup() {
    return tg;
  } // SimulationFrame.getThreadGroup

  /**
   * Liefert wahr im Falle der Server-Umgebung
   * @see SimulationFrame#getServer
   * @see SimulationServer
   */

  public final boolean isServer() {
    return isServer;
  } // SimulationFrame.isServer

  /**
   * Liefert wahr im Falle der Client-Umgebung
   * @see SimulationFrame#getClient
   * @see SimulationClient
   */

  public final boolean isClient() {
    return isClient;
  } // SimulationFrame.isClient

  /**
   * Liefert den zugrundeliegenden Server
   * @see SimulationFrame#isServer
   * @see SimulationFrame#getClient
   * @see SimulationServer
   */

  public final SimulationServer getServer() {
    return server;
  } // SimulationFrame.getServer


  /**
   * Liefert den zugrundeliegenden Server
   * @see SimulationFrame#isClient
   * @see SimulationFrame#getServer
   * @see SimulationClient
   */

  public final SimulationClient getClient() {
    return client;
  } // SimulationFrame.getClient

  /**
   * Zeichnet den Frame
   */


  public void paint( Graphics gc ) {
    while ( !initialized ) {
      Thread.yield();
    } // while
    textArea.repaint();
    index.repaint();
  } // SimulationFrame.paint
    
  /**
   * Zeichnet alle Beschriftungen neu
   * @see SimulationFrame#paint
   */

  void redrawLabels() {
    simulation.setText( text );
    setTitle( text.frameTitle );
    windowMenu.setLabel( text.menuBar_windowButtonText );
    quitMenuItem.setLabel( text.menuBar_windowButton_QuitButtonText );
    changeLanguageMenuItem.setLabel( text.menuBar_windowButton_ChangeLanguageButtonText );
    editMenu.setLabel( text.menuBar_editButtonText );
    simulationSpeedMenu.setLabel( text.menuBar_editButton_simulationSpeedButtonText );
    simulationSpeedSlowMenuItem.setLabel( text.menuBar_editButton_simulationSpeedButton_slowButtonText );
    simulationSpeedNormalMenuItem.setLabel( text.menuBar_editButton_simulationSpeedButton_normalButtonText );
    simulationSpeedFastMenuItem.setLabel( text.menuBar_editButton_simulationSpeedButton_fastButtonText );

    startDemoMenuItem.setLabel( text.menuBar_editButton_startDemoButtonText );
    newMenuItem.setLabel( text.menuBar_editButton_newButtonText );
    helpMenu.setLabel( text.menuBar_helpButtonText );
    infoMenuItem.setLabel( text.menuBar_helpButton_InfoButtonText );
    introductionMenuItem.setLabel( text.menuBar_helpButton_IntroductionButtonText );
    speechLanguageMenuItem.setLabel( text.menuBar_windowButton_SpeechLanguageButtonText );
    repaint();
  } // SimulationFrame.redrawLabels


  public boolean handleEvent( Event evt ) {
    if ( evt.id == Event.WINDOW_DESTROY && evt.target == this ) {
      this.hide();
      this.dispose();
    } else {
      return super.handleEvent( evt );
    } // if
    return true;
  } // SimulationFrame.handleEvent

  /**
   * Liefert die Textkomponente, die sich unten im Frame befindet
   */

  public final TextArea getTextArea() {
    return textArea;
  } // SimulationFrame.getTextArea

  /**
   * Setze die Animationsgeschwindigkeit auf den Wert des Parameters
   * @see SimulationFrame#getAnimationSpeed
   */
  
  public final void setAnimationSpeed( int i ) {
    animationSpeed = i;
  } // SimulationFrame.setAnimationSpeed


  /** 
   * Liefert die aktuelle Animationsgeschwindigkeit
   * @see SimulationFrame#setAnimationSpeed
   */

  public final int getAnimationSpeed() {
    return animationSpeed;
  } // SimulationFrame.getAnimationSpeed


  /**
   * Liefert wahr falls die Demonstration aktiv ist
   * @see SimulationFrame#demoOn
   * @see SimulationFrame#demoOff
   */

  public final boolean demoRunning() {
    return demoRunning;
  } // SimulationFrame.simulationRunning

  /**
   * Signalisiert, dass die Demo aktiviert wurde
   * @see SimulationFrame#demoOff
   * @see SimulationFrame#demoRunning
   */

  public final void demoOn() {
    demoRunning = true;
    index.repaint();
  } // SimulationFrame.demoOn

  /**
   * Signalisiert, dass die Demo beendet ist
   * @see SimulationFrame#demoOff
   * @see SimulationFrame#demoRunning
   */

  public final void demoOff() {
    demoRunning = false;
    index.repaint();
  } // SimulationFrame.demoOff

  /**
   * Aktualisiert die Zustaende der Buttons im ButtonPanel
   * @see ButtonPanel
   */

  public void resetButtons() {
  } // SimulationFrame.resetButtons

} // SimulationFrame  

